package org.example.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.entity.User;

import java.util.List;

public interface UserMapper {
    // mapper即数据映射器,用于实现Java对象与数据库数据之间的转换
    // 虽然UserMapper没有实现类,但是mybatis通过动态代理为mapper接口生成实现类
    // spring通过@ComponentScan注解扫描到Mapper接口,并将其注册为Bean

    @Insert("insert into t_user(id,username,password) values(#{id},#{username},#{password})")
    void insert(User user);

    @Update("update t_user set username=?,password=? where id = #{id}")
    void update(User user);

    @Delete("delete from t_user where id = #{id}")
    void deleteById(String id);

    @Select("select * from t_user")
    List<User> getAll();

    @Select("select * from t_user where id = #{id}")
    User getById(String id);

    User getById1(String id);
}
